# https://www.w3cschool.cn/flask/
# https://read.helloflask.com/
from flask import Flask,render_template,request,Response
from gevent import pywsgi
import os
import json
from werkzeug.utils import secure_filename

app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = 'upload/'

@app.route('/')
def hello():
    return 'Welcome to My Watchlist!'

@app.route('/admin')
def admin():
    return render_template("admin/admin.html")

@app.route('/uploader',methods=['POST'])
def uploader():
    if request.method == 'POST':
        type = request.form.get("type")
        f = request.files['file']
        f.save(os.path.join(app.config['UPLOAD_FOLDER'], secure_filename(f.filename)))
        jsonData = {
            'code':1,
            'type':type

        }
        return Response(json.dumps(jsonData),mimetype='application/json')

if __name__ == "__main__":
    ## app.run("127.0.0.1","8088")
    server = pywsgi.WSGIServer(('0.0.0.0', 8088), app)
    server.serve_forever()